package br.com.exceptiongroup.chatexception.service;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;

import br.com.exceptiongroup.chatexception.model.BaseBean;

public abstract class BaseMongoService <T extends BaseBean> {
	
	@Resource
	protected MongoTemplate template;
	
	private Class<T> clazz;
	
	public BaseMongoService(Class<T> clazz) {
		this.clazz = clazz;
	}
	
	public void save(T document) {
		template.save(document);
	}
	
	public void remove(T document) {
		template.remove(document);
	}
	
	public T findById(Serializable id) {
		return template.findById(id, clazz);
	}
	
	public List<T> listAll() {
		return template.findAll(clazz);
	}
	
	public List<T> findByQuery(Query query) {
		return template.find(query, clazz);
	}
	
	
	
	
}
